package kr.hkit.PowerJava.chapter25;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

public class ParseURLExample {
public static void main(String[] args) {
	try {
		StringBuilder sb = new StringBuilder();
		URL myURL = new URL("http://www.hkit.kr/SUB/?ctId=49&eduCode=00000027:80");
		sb.append("protocol = " + myURL.getProtocol()+"\n");
		sb.append("authority = " + myURL.getAuthority()+"\n");
		sb.append("host = " + myURL.getHost()+"\n");
		sb.append("port = " + myURL.getPort()+"\n");
		sb.append("path = " + myURL.getPath()+"\n");
		sb.append("query = " + myURL.getQuery()+"\n");
		sb.append("filename = " + myURL.getFile()+"\n");
		sb.append("ref = " + myURL.getRef()+"\n");
		System.out.println(sb);
		
		System.out.println("====================================");
		BufferedReader in = new BufferedReader(new InputStreamReader(myURL.openStream()));
		String line;
		while((line=in.readLine())!=null){
			System.out.println(line);
		}
		in.close();
	} catch (MalformedURLException e) {
		
		System.out.println("잘못된 주소입니다. ");
	} catch (IOException e) {
		e.printStackTrace();
	}
	
}
}
